<script setup>
import {ref} from 'vue'
import {addDynamic} from '@/api/dynamic'
import { useRouter } from 'vue-router';
import { QuillEditor } from '@vueup/vue-quill'
import '@vueup/vue-quill/dist/vue-quill.snow.css'
// import '@vueup/vue-quill/dist/vue-quill.bubble.css';
const router=useRouter()
const formModel=ref({
    title: '',
    content: '',

})


const rules={
    title:[
        {required: true,message: '请输入标题'}
    ],
    content:[
        {required: true,message: '请输入内容'}
    ]
}

const form=ref()

const onSubmit = async()=>{
    await form.value.validate()
    console.log(formModel.value.title)
    const res=await addDynamic(formModel.value.title,formModel.value.content)
    //路由跳转主页
    console.log(res)
    router.replace('/home')
    ElMessage.success("发布动态成功");
}

</script>
<template>
    <div style="margin-left: 30%;">
    <el-form ref="form" :model="formModel" :rules="rules" label-width="auto" style="max-width: 600px">
    <el-form-item label="标题" prop="title">
      <el-input v-model="formModel.title" />
    </el-form-item>
    
    <el-form-item  label="内容" prop="content">
      <!-- <el-input :rows="15" v-model="formModel.content" type="textarea"  /> -->
      <div class="editor">
      <quill-editor
            ref="editorRef"
            theme="snow"
            v-model:content="formModel.content"
            contentType="html"
          >
          </quill-editor>
        </div>
    </el-form-item>
    
    <el-form-item>
      <el-button type="primary" @click="onSubmit">发布</el-button>
    </el-form-item>
  </el-form>
    </div>
</template>

<style lang="scss" scoped>

  
.editor {
  width: 100%;
  :deep(.ql-editor) {
    min-height: 200px;
  }
}
</style>